const request = require('../../request/index')

/**
 * @desc 通过某些搜索引擎的下拉词获取推荐列表
 * @param keyword
 */
async function getSuggest(keyword) {
    let url = `https://www.baidu.com/sugrec?wd=${encodeURI(keyword)}&prod=pc`
    let suggestList = await request.get(url)
    let resObject = {}
    resObject.url = url
    resObject.keyword = keyword
    if (suggestList === undefined) return [keyword]
    resObject.searchList = suggestList.g
    return resObject
}

module.exports = exports = getSuggest